package com.xiaobaibai.security.login.dao;

import com.xiaobaibai.server.user.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

@Component
public class LoginUserDetailService implements UserDetailsService {

    @Autowired
    private IUserService userService;

    @Override
    public UserDetails loadUserByUsername(String userId) throws UsernameNotFoundException {

        String password=userService.getPasswordByUserId(userId);

        //四个boolean 可用  没过期  密码没过期  是否没被锁定
        return new User(userId,password,true,true,
                true,true,
                //作用:把一个带有','的String 转为权限的List
                AuthorityUtils.commaSeparatedStringToAuthorityList("ADMIN"));
    }

}
